package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author ChaunceyZhang
 * @date 2022-10-18 16:06
 * @blog1 https://zephyr-cyber.github.io/
 * @blog2 https://www.yuque.com/gougougou-xwscx
 */
@Component
@Aspect
public class ProcessDataAdvice {
    @Pointcut("execution(* com.itheima.service.impl.*ServiceImpl.*(..))")
    public void pt(){}


    @Around("pt()")
    public Object processDate(ProceedingJoinPoint pjp) throws Throwable {
        Object[] args = pjp.getArgs();
        if(args != null && args.length > 0){
            for (int i = 0; i < args.length; i++) {
                if(args[i] instanceof String){
                    String arr = (String) args[i];
                    args[i] = arr.trim();
                }
            }
        }
        Object result = pjp.proceed(args);
        return result;
    }
}
